<?php
/**
 * Short desc
 * 
 * Created by JetBrains PhpStorm.
 * @author zadoev@gmail.com
 * @version 29.03.11 15:28
 * @package ${END}
 */
 

class RModelAdmin
{
	protected $_model;

	public function __construct( $model )
	{
		$this->_model = $model;
	}

	public function getGridColumns( $last = array())
	{
		$columns = array();

		$excludeFields = $this->getAdminExcludedFields();
		foreach ( $this->getAdminFields() as $field )
		{
			if ( in_array($field, $excludeFields ) )
				continue;
			if ( is_array($field) )
			{
				$columns[] = $field;
				continue;
			}

			$columns[] = $this->_model->getField($field)->asGridColumn();
		}
		if ( $last )
			$columns[] = $last;

		return $columns;
	}

	public function getViewAttributes()
	{
		$attributes = array();

		$excludeAttributes = $this->getViewExcludedFields();
		foreach ( $this->getViewFields() as $field )
		{
			if ( in_array($field, $excludeAttributes ) )
				continue;
			if ( is_array($field) )
			{
				$attributes[] = $field;
				continue;
			}

			$attributes[] = $this->_model->getField($field)->asViewAttribute();
		}
		return $attributes;

	}

	public function getViewExcludedFields()
	{
		return array();
	}

	public function getAdminExcludedFields()
	{
		return array();
	}

	public function getViewFields()
	{
		return array_keys($this->_model->getAttributes());
	}

    public function getSearchFields()
    {
        return array_keys($this->_model->getAttributes());
    }

	public function getAdminFields()
	{
		return array_keys($this->_model->getAttributes());
	}

	public function getTitle()
	{
		return 'Manage ' . $this->_model->tableName();
	}

    public function getFormFields()
    {
        return array_keys($this->_model->getAttributes());        
    }

}